<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in products" :key="index">
                <input type="checkbox" v-model="item.choose" @click="chooseItem(index)">
                {{item.name}}
            </li>
        </ul>
        <br>
        全选：
        <input type="checkbox" v-model="allChoose" @click="chooseAll">
    </div>
    <script src="./vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:{
                products:[
                    {
                        name:'衬衫',
                        price:123,
                        choose:false
                    },
                    {
                        name:'裤子',
                        price:12,
                        choose:false
                    },
                    {
                        name:'裙子',
                        price:124,
                        choose:false
                    }
                ],
                allChoose:false
            },
            methods:{
                chooseAll(){
                    this.allChoose = !this.allChoose;
                    this.products.forEach(item => {
                        item.choose = this.allChoose
                    })
                },
                chooseItem(index){
                    this.products[index].choose = !this.products[index].choose;
                    this.allChoose = this.products.every((item) => {
                        return item.choose
                    })
                }
            }
        })
    </script>
</body>
</html>


